package controller
////
import (
	"context"
	v1 "{{.table.ModuleName}}/api/v1"
	"{{.table.ModuleName}}/internal/model"
	"{{.table.ModuleName}}/internal/service"
	"github.com/gogf/gf/v2/util/gconv"
)
////
var (
	{{.table.ClassName}} = c{{.table.ClassName}}{}
)
type c{{.table.ClassName}} struct{}
////
func (c *c{{.table.ClassName}}) PageList(ctx context.Context, req *v1.{{.table.ClassName}}PageListReq) (res *v1.{{.table.ClassName}}PageListRes, err error) {
	in := new(model.{{.table.ClassName}})
	err = gconv.Struct(req, in)
	if err != nil {
		return nil, err
	}
	total, list, err := service.{{.table.ClassName}}().PageList(ctx, in)
	if err != nil {
		return nil, err
	}
	res = &v1.{{.table.ClassName}}PageListRes{
		Total: total,
		Rows:  list,
	}
	return
}
////
func (c *c{{.table.ClassName}}) List(ctx context.Context, req *v1.{{.table.ClassName}}ListReq) (res *v1.{{.table.ClassName}}ListRes, err error) {
	in := new(model.{{.table.ClassName}})
	err = gconv.Struct(req, in)
	if err != nil {
		return nil, err
	}
	list, err := service.{{.table.ClassName}}().List(ctx, in)
	if err != nil {
		return nil, err
	}
	res = &v1.{{.table.ClassName}}ListRes{
		Rows: list,
	}
	return
}
////
func (c *c{{.table.ClassName}}) Add(ctx context.Context, req *v1.{{.table.ClassName}}AddReq) (res *v1.{{.table.ClassName}}AddRes, err error) {
	in := new(model.{{.table.ClassName}})
	err = gconv.Struct(req, in)
	if err != nil {
		return nil, err
	}
	err = service.{{.table.ClassName}}().Add(ctx, *in)
	return
}
////
func (c *c{{.table.ClassName}}) Edit(ctx context.Context, req *v1.{{.table.ClassName}}EditReq) (res *v1.{{.table.ClassName}}EditRes, err error) {
	in := new(model.{{.table.ClassName}})
	err = gconv.Struct(req, in)
	if err != nil {
		return nil, err
	}
	err = service.{{.table.ClassName}}().Edit(ctx, *in)
	return
}
////
func (c *c{{.table.ClassName}}) Delete(ctx context.Context, req *v1.{{.table.ClassName}}DelReq) (res *v1.{{.table.ClassName}}DelRes, err error) {
	err = service.{{.table.ClassName}}().Delete(ctx, req.Ids)
	return
}
